package com.thrd.basicframework.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author: ${唐杰}
 * @date: 2021/4/7
 */
public class TimeUtils {

    //四、将字符串转为时间戳
    public static long getStringToDate(String dateString, String pattern) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
        Date date = new Date();
        try{
            date = dateFormat.parse(dateString);
        } catch(ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return date.getTime();
    }

    //三、时间戳转换成字符窜
    public static String getDateToString(long milSecond, String pattern) {
        Date date = new Date(milSecond);
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        return format.format(date);
    }

    public static String getFormatConversion(String dateString){
        long data=getStringToDate(dateString,"yyyy-MM-dd HH:mm:ss");
        return getDateToString(data,"yyyy-MM-dd");
    }

}
